#ifndef CAN_RECEIVE_H
#define CAN_RECEIVE_H

#include "struct_typedef.h"

//DM4310_limit（默认参数，特殊的在“CAN_receive.c”里改）
#define P_MIN -12.5  	//位置最小值
#define P_MAX 12.5		//位置最大值
//#define P_MIN -6.28  	//位置最小值
//#define P_MAX 6.28		//位置最大值
#define V_MIN -45	  	//速度最小值
#define V_MAX 45	  	//速度最大值
#define KP_MIN 0.0		//Kp最小值
#define KP_MAX 500.0	//Kp最大值
#define KD_MIN 0.0		//Kd最小值
#define KD_MAX 5.0		//Kd最大值
#define T_MIN_4310 -18	//转矩最小值
#define T_MAX_4310 18	//转矩最大值

//达妙各模式偏移量
#define MIT_MODE		0x000
#define SPEED_POS_MODE	0x100
#define SPEED_MODE		0x200

/* CAN1 send and receive ID */
typedef enum
{
    /* 达妙ID设置建议：MASTER ID > SLAVE_ID */
    //send ID
    CAN_DM1_SLAVE_ID = 0x000 + MIT_MODE,
    
    //receive ID
    CAN_DM1_MASTER_ID = 0x001,

} can1_msg_id_e;

//dm motor data
typedef struct
{
    uint8_t id;
    uint8_t err;
    int p_int;
    int v_int;
    int t_int;
    fp32 p_fp32;
    fp32 v_fp32;
    fp32 t_fp32;
    fp32 T_MOS;
    fp32 T_Rotor;
    uint16_t ecd; 
    uint16_t last_ecd; 
    int last_p_int;
} dm_motor_measure_t;

extern void CAN_cmd_DMmotor_clear_errors(uint16_t id);
extern void CAN_cmd_DMmotor_enable(uint16_t id);
extern void CAN_cmd_DMmotor_failure(uint16_t id);
extern void CAN_cmd_DMmotor_save_zero(uint16_t id);
extern void CAN_cmd_DMmotor4310_MIT(uint16_t id, float _pos, float _vel, float _KP, float _KD, float _torq);
extern void CAN_cmd_DMmotor_speed_pos(uint16_t id, float _pos, float _vel);
extern void CAN_cmd_DMmotor_speed(uint16_t id, float _vel);

extern const dm_motor_measure_t *get_dm_motor_1_measure_point(void);

#endif
